package com.yanxi.controller;

import com.yanxi.pojo.User;
import com.yanxi.service.UserService;
import com.yanxi.service.impl.UserServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
//    方式一
    /*@Autowired
    private UserService userService ;*/
//    方式二
/*    private UserService userService;
    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }*/
    private UserService userService;
  //  @Qualifier("userServiceImpl")
  //  @Autowired
    @Resource(name = "userService")
    public void setUserService(UserService userService) {
        this.userService = userService;
    }


    @RequestMapping("/list")
    public List<User> list(){
        //1.调用service层,获取用户信息
        List<User> userList = userService.findAll();
        //2.返回用户信息( JSON格式)
        return userList;
    }

}
